package com.heitian.ssm.controller;

import com.heitian.ssm.model.HelpEntity;
import com.heitian.ssm.service.HelpService;


import com.heitian.ssm.utils.FastJsonUtils;
import com.heitian.ssm.utils.JedisUtils;
import com.heitian.ssm.utils.JsonResultUtils;
import com.heitian.ssm.utils.Result;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Created with IntelliJ IDEA.
 * User: mishuai
 * Date: 2018-04-29
 * Time: 15:42
 * Des:
 */
@Controller
@RequestMapping("/test")
public class XiaoChengXuDemo {
    private Logger log = Logger.getLogger(XiaoChengXuDemo.class);

    @Autowired
    private HelpService helpService;


    @RequestMapping("/indexContent")
    @ResponseBody
    public void indexContent(HttpServletRequest request, HttpServletResponse response) {
        log.info("查询所有用户信息主页");
        HelpEntity helpEntity = helpService.selectHelp();

        /*JedisPool jedisPool = new JedisPool("140.143.198.38", 6379);
        //从连接池中获得一个连接
        Jedis jedis = jedisPool.getResource();
        jedis.set("test", "hello jedis");*/

        if (helpEntity == null) {

            JsonResultUtils.ajaxReturn(response, FastJsonUtils.toJSONString(Result.falseReturnCodeMsg("F_99999", "插入数据失败")));
        } else {
           // log.info(jedis.get("test"));
            JedisUtils.set("helpEntity5",FastJsonUtils.toJSONString(helpEntity));
            log.info("+++redis+++"+ JedisUtils.get("helpEntity5"));

            JsonResultUtils.ajaxReturn(response, FastJsonUtils.toJSONString(Result.successReturn(helpEntity)));
        }
    }
}
